<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/10/28
 * Time: 10:22
 */

namespace app\adminapiv3\controller;

//ip白名单
use think\Request;

class ServerAllowIp extends Base
{
    /**
     * @name 列表
     * @author wx
     * @date 2019/10/28 10:26
     */
    public function list()
    {
        //接收参数
        $params['ip'] = $this->filterInput('ip','get');
        $params['login_time'] = $this->filterInput('login_time','get');


        $server = new \app\adminapiv3\service\ServerAllowIp();
        $list = $this->toDo([$server, 'list'], [$params, $this->getLimit()]);

        $this->jsonOutPut($list);
    }

    /**
     * @name 添加
     * @author wx
     * @date 2019/10/28 10:26
     */
    public function add()
    {
        $params['ip'] = $this->filterInput('ip*','post');

        $server = new \app\adminapiv3\service\ServerAllowIp();
        $this->toDo([$server, 'add'], [$params]);

        $this->jsonOutPut();
    }

    /**
     * @name 编辑
     * @author wx
     * @date 2019/10/28 10:27
     */
    public function modify()
    {
        global $logContent;
        $logContent = '修改信任主机';

        $id = $this->filterInput('id*','post');
        $params['ip'] = $this->filterInput('ip*','post');

        $server = new \app\adminapiv3\service\ServerAllowIp();
        $this->toDo([$server, 'modify'], [$id, $params]);

        $this->jsonOutPut();
    }

    /**
     * @name 删除
     * @author wx
     * @date time
     */
    public function del()
    {
        global $logContent;
        $logContent = '删除信任主机';

        $id = $this->filterInput('id*','post');

        $server = new \app\adminapiv3\service\ServerAllowIp();
        $this->toDo([$server, 'del'], [$id]);

        $this->jsonOutPut();
    }

    /**
     * @name 功能设置
     * @author wx
     * @date 2021/1/7 10:03
     */
    public function setting(Request $request)
    {
        $server = new \app\adminapiv3\service\ServerAllowIp();
        if ($request->isGet()) {

            $data = $server->setting('get');

        }else{

            global $logContent;
            $logContent = '修改功能设置';

            $data['time_range'] = $this->filterInput('time_range*','post');
            $data['status'] = $this->filterInput('status*','post');
            $server->setting('post', $data);
        }

        $this->jsonOutPut($data);
    }


}